package com.example.myfirstapp;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import controller.BaseActivity;

public class MainActivity extends BaseActivity {
    public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = (Button) findViewById(R.id.button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.v("MainActivity", "Button Clicked!");
                sendMessage(v);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.create_room:
                Toast.makeText(this, "Room Created!", Toast.LENGTH_SHORT).show();
                CreateRoomActivity.startAction(MainActivity.this);
                break;
            case R.id.join_room:
                Toast.makeText(this, "Join Room!", Toast.LENGTH_SHORT).show();
                JoinRoomActivity.startAction(MainActivity.this);
                break;
        }

        return true;
    }

    /**
     * Called when the user taps the Send button
     */
    public void sendMessage(View view) {

        // get target object & get target innerText
        EditText editText = (EditText) findViewById(R.id.editText);
        String mes = editText.getText().toString();

        // Active Another Intent
        // and put extra string
        DisplayMessageActivity.actionStart(MainActivity.this, EXTRA_MESSAGE, mes);

    }

    public void actionStart(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        context.startActivity(intent);
    }
}